'use strict';
var $form=$("form");
$form.validate({
    /**
     * ignore：忽略某些元素不验证
     * @type {String}
     * 例如：ignore: ".ignore" ，忽略所有的带ignore class 的标签
     */
    ignore: ".ignore"
});
window.formObject=$form;
var userInfo=common.getLocalData(common.agentSysCacheWord).user;
var selfUserId=common.getQueryString("userId");
var $department=$(".department");
var $roleName=$(".roleName");
//根据用户id获取用户详情信息
$.post(window.globalHost + '/agent-sys/admin/user/getDetail.do', {id:selfUserId}).success(function(data) {
    var detailInfo = common.transformData(data);
    //初始化所有input的值
    common.initInputByName(detailInfo);
    $("#loginName").html(detailInfo.loginName);
    $("#userName").html(detailInfo.userName);
    //创建根据部门联动职务的下拉列表，并初始化当前部门和职务下拉列表
    buildSelect.buildRoleListByDepartment({
        departmentSelector:$department,
        roleSelector:$roleName,
        initFatherChecked:detailInfo.departId,
        initSonChecked:detailInfo.roleId
    });
    var headerPhotoGallery=$("#header-photo").gallery({
        readOnly:false,
        title:"上传用户头像",
        url:window.globalHost +common.uploadImagePort,
        paramName:"uploadData",
        fileFolder:{folder:"user",id:userInfo.id,fileName:"sys_user_"+new Date().getTime()},
        returnPathName:"filePath",
        maxFiles:1,
        filePaths:detailInfo.photo?[detailInfo.photo]:[],
        uploadCallback:function () {
            var path=headerPhotoGallery.getFilePaths();
            $("#photo").val(!!path.length?path.join(","):"")
        },
        deleteCallback:function () {
            var path=headerPhotoGallery.getFilePaths();
            $("#photo").val(!!path.length?path.join(","):"");
        }
    });
});

